package com.rabbitmq.learn.common;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Lxk on 2019/8/11.
 */
public class ConnectionUtils {

    /**
     * 获取mq连接
     * @return
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();

        connectionFactory.setHost("127.0.0.1");

        connectionFactory.setPort(5672);

        connectionFactory.setVirtualHost("/vhost_test");

        connectionFactory.setUsername("guest");

        connectionFactory.setPassword("guest");

        return connectionFactory.newConnection();
    }

}
